﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Core.Entities;

/// <summary>
/// 文件
/// </summary>
//[SplitTable(SplitType.Year)]//按年分表
//[SugarTable("Sys_Files_{year}{month}{day}", tableDescription: "文件")]
[SugarTable("Sys_Files", tableDescription: "文件")]
//[SugarIndex("Index_{table}_FileType_Name{include:FileType,Name}", nameof(FileType), OrderByType.Asc)]
[SugarIndex("Index_{table}_CreationTime", nameof(SysFiles.CreationTime), OrderByType.Desc)]
[SugarIndex("Index_{table}_PID", nameof(SysFiles.PID), OrderByType.Desc)]
[SugarIndex("Index_{table}_FileType", nameof(SysFiles.FileType), OrderByType.Desc)]
[SugarIndex("Index_{table}_FileStorageType", nameof(SysFiles.FileStorageType), OrderByType.Desc)]
[SugarIndex("Index_{table}_Name", nameof(SysFiles.Name), OrderByType.Desc)]
[SugarIndex("Index_{table}_Extension", nameof(SysFiles.Extension), OrderByType.Desc)]
[SugarIndex("Index_{table}_Type", nameof(SysFiles.Type), OrderByType.Desc)]
[SugarIndex("Index_{table}_FileObjectName", nameof(SysFiles.FileObjectName), OrderByType.Desc)]
[SugarIndex("Index_{table}_SourceDataId", nameof(SysFiles.SourceDataId), OrderByType.Desc)]
[SugarIndex("Index_{table}_SourceDataType", nameof(SysFiles.SourceDataType), OrderByType.Desc)]
[SugarIndex("Index_{table}_IsOpenFile", nameof(SysFiles.IsOpenFile), OrderByType.Desc)]
public class SysFiles : FullEntityNoIdentity, IExtensionData
{
    /// <summary>
    /// <summary>
    /// Json数据 
    /// </summary>
    [SugarColumn(ColumnDescription = "扩展字段", ColumnDataType = StaticConfig.CodeFirst_BigString, IsJson = true, IsNullable = true)]
    public Dictionary<string, object>? ExtensionData { get; set; }

    /// <summary>
    /// 父ID
    /// </summary>
    [Comment("PID")]
    public long PID { get; set; }

    /// <summary>
    /// 文件类型
    /// </summary>
    [Comment("文件类型")]
    public FileType FileType { get; set; }

    /// <summary>
    /// 文件存储类型
    /// </summary>
    [Comment("文件存储类型")]
    public FileStorageType FileStorageType { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    [Comment("名称")]
    [MaxLength(500)]
    public string Name { get; set; }
    /// <summary>
    /// 扩展名
    /// </summary>
    [Comment("扩展名")]
    [MaxLength(500)]
    public string Extension { get; set; }
    /// <summary>
    /// 大小
    /// </summary>
    [Comment("大小")]
    public int Size { get; set; }
    /// <summary>
    /// 分类
    /// </summary>
    [Comment("分类")]
    [MaxLength(100)]
    public string Type { get; set; }

    /// <summary>
    /// 存储到bucket的名称（文件唯一标识id）
    /// </summary>
    [Comment("存储到bucket的名称")]
    [MaxLength(200)]
    public string FileObjectName { get; set; }

    /// <summary>
    /// 存储路径
    /// </summary>
    [Comment("存储路径")]
    [MaxLength(500)]
    public string FilePath { get; set; }


    /// <summary>
    /// 是否开放文件
    /// 开放的文件，任何人都可以访问读取
    /// </summary>
    [Comment("是否开放文件")]
    public bool IsOpenFile { get; set; }

    /// <summary>
    /// 层级
    /// </summary>
    [Comment("层级")]
    public int Level { get; set; }

    /// <summary>
    /// 层级路径
    /// 格式 a/b/c
    /// </summary>
    [Comment("层级路径")]
    [MaxLength(500)]
    public string LevelPath { get; set; }

    #region ref
    /// <summary>
    /// 来源数据ID
    /// </summary>
    [Comment("来源数据ID")]
    public int SourceDataId { get; set; }

    /// <summary>
    /// 来源数据类型
    /// </summary>
    [Comment("来源数据类型")]
    [MaxLength(500)]
    public string SourceDataType { get; set; }
    #endregion

}

/// <summary>
/// 文件类型
/// </summary>
public enum FileType
{
    文件 = 0,
    目录 = 1,


}
